/*
** my_getnbr_base.c for  in /home/gueux_g/projet/code_source
**
** Made by gregory gueux
** Login   <gueux_g@epitech.net>
**
** Started on  Thu Oct 11 02:38:56 2012 gregory gueux
** Last update Thu Oct 11 20:36:57 2012 gregory gueux
*/

int      init(char *base, int *nbr, int *j, int *i)
{
  int           len;

  len = my_strlen(base);
  *nbr = 0;
  *j = 0;
  *i = 1;
  return (len);
}

int             my_getnbr_base(char *str, char *base)
{
  int           nbr;
  int           len;
  int           j;
  int           k;
  int           i;

  len = init(base, &nbr, &j, &i);
  k = 0;
  if (str[j] == '-')
    {
      j = 1;
      i = -1;
    }
  while (str[j] != '\0')
    {
      while (k <= len && base[k] != str[j])
        k++;
      if (base[k] == str[j])
        nbr = nbr * len + k;
      else
        return (0);
      j++;
      k = 0;
    }
  return (nbr * i);
}
